//
// Created by martin on 2021/5/30.
//

#include <sys/stat.h>
#include <stdio.h>
#include "directory.h"

void print_size(char *name, char *type)
{
    struct stat statbuf;
    int ret;

    ret = stat(name, &statbuf);
    if (ret < 0) {
        perror("stat error");
        return;
    }

     printf("%s, type = %s, size = %ld bytes\n", name, type, statbuf.st_size);
}

/**
 * 遍历所有目录, 并打印文件名称和尺寸
 */
int main(int argc, char *argv[])
{
    char *s = "/home/martin/文档/资料_Linux";

    if (argc == 2) {
        s = argv[1];
    }

    directory_walk(s, print_size);
    return 0;
}